/*
 * Copyright 2013-2020 the original author or authors.
 *
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 *      https://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */
package org.ligson.hbase127.support;

import org.ligson.hbase127.core.HBaseOperations;
import org.ligson.hbase127.core.HBaseRepositoryFactory;
import org.springframework.data.hadoop.hbase.HbaseTemplate;
import org.springframework.data.repository.Repository;
import org.springframework.data.repository.core.support.RepositoryFactoryBeanSupport;
import org.springframework.data.repository.core.support.RepositoryFactorySupport;
import org.springframework.util.Assert;

import java.io.Serializable;

/**
 * Spring {@link org.springframework.beans.factory.FactoryBean} implementation to ease container based configuration for
 * XML namespace and JavaConfig.
 *
 * @author Rizwan Idrees
 * @author Mohsin Husen
 * @author Mark Paluch
 */
public class HbaseRepositoryFactoryBean<T extends Repository<S, ID>, S, ID extends Serializable> extends
        RepositoryFactoryBeanSupport<T, S, ID> {

    private HBaseOperations hbaseOperations;
    private HbaseTemplate hbaseTemplate;

    /**
     * Creates a new {@link } for the given repository interface.
     *
     * @param repositoryInterface must not be {@literal null}.
     */
    public HbaseRepositoryFactoryBean(Class<? extends T> repositoryInterface) {
        super(repositoryInterface);
    }

    /*
     * (non-Javadoc)
     * @see org.springframework.data.repository.core.support.RepositoryFactoryBeanSupport#afterPropertiesSet()
     */
    @Override
    public void afterPropertiesSet() {
        super.afterPropertiesSet();
        Assert.notNull(hbaseTemplate, "hbaseTemplate must be configured!");
    }

    @Override
    protected RepositoryFactorySupport createRepositoryFactory() {
        // return new HbaseRepositoryFactoryBean(operations);
        return new HBaseRepositoryFactory(hbaseTemplate);
    }

    public HBaseOperations getHbaseOperations() {
        return hbaseOperations;
    }

    public void setHbaseOperations(HBaseOperations hbaseOperations) {
        this.hbaseOperations = hbaseOperations;
    }

    public HbaseTemplate getHbaseTemplate() {
        return hbaseTemplate;
    }

    public void setHbaseTemplate(HbaseTemplate hbaseTemplate) {
        this.hbaseTemplate = hbaseTemplate;
    }
}
